/******************************************************************************
 * Name: TraceManager.h
 * Author: ZhengJuyu, zhengjuyu@gmail.com
 * Date: 2008/08/24
 * Revision history:
 *
 * Purpose:
 *     Do the basic optimization "trace linking" on basic block 
 *
 *****************************************************************************/
#ifndef TRACEMANAGER_H
#define TRACEMANAGER_H

#include "crossbit/MemoryManager.h"
#include "crossbit/TBlock.h"

namespace crossbit
{
		class TraceManager
		{
				public:
						TraceManager( MemoryManager *mm ) : tm_mm(mm)
						{
								tm_pool = mm->allocateExecutable(POOL_SIZE);
								tm_size = POOL_SIZE;
								UTIL::XTMemset( (void*)tm_pool, 0, tm_size );
						}

						virtual ~TraceManager() {}

						//direct control transfer's linking, link preBlock's specified exit to next block
						virtual void directLinkTo( TBlock* preBlock, XTInt32 exit, TBlock* block) {}

						//indirect control transfer's linking
						virtual void indirectLinkTo( TBlock* preBlock, XTInt32 exit, TBlock* block ) {}

						//link the old basic tblock to the super block with the same spc
						virtual void linkSuperBlock( TBlock* former_tblock , TBlock* super_tblock){} 
				protected:

						virtual void fillPredictionCodeBlock( TBlock* block ) {}

						virtual XTMemAddr allocatePredictionCodeBlock() {}

						XTMemAddr tm_pool;
						XTUint32 tm_size;

						static const XTUint32 POOL_SIZE = 0x00100000;

						MemoryManager *tm_mm;

		};
}

#endif	//TRACEMANAGER_H
